from public.action import *
from public.business import *
from public.testData import *
from public.tools import *
import time

testCase = "DBshop009_商品管理管理商品添加商品"

firefox = openBrowser(urlAdmin) #打开后台网页
DBshopLoginAdmin(firefox)   #后台登录

DBshopEnterMenu2(firefox,"商品管理","管理商品")

s=firefox.find_element_by_xpath("//p[@style='font-size: 16px; line-height: 30px;']").text
print(s)
l = "管理商品 - \(商品数："
r = "\)"
num = reGetString(s,l,r)
print(num)

# 1.点击添加商品按钮，商品名称填写“苹果XR”,本店价格“7999”，商品类型“虚拟商品”。
firefox.find_element_by_xpath("(//a[@class='btn btn-small btn-primary'])[1]").click()
firefox.find_element_by_id("goods_name").send_keys("苹果XR")
firefox.find_element_by_id("goods_shop_price").send_keys("7999")
firefox.find_element_by_xpath("//select[@id='goods_type']/option[3]").click()
# 2.点击“保存商品”按钮，后台保存成功添加的商品。
firefox.find_element_by_xpath("(//button[@class='btn btn-small btn-primary'])[1]").click()

s=firefox.find_element_by_xpath("//p[@style='font-size: 16px; line-height: 30px;']").text
print(s)
l = "管理商品 - \(商品数："
r = "\)"
num1 = reGetString(s,l,r)
print(num1)

if int(num1) == int(num)+1:
    writeLog("%s 测试通过" % testCase)
else:
    writeLog("%s 测试不通过" % testCase)
    getPhoto(firefox)
firefox.quit()

